class Solution
{
public:
    int maximumXorProduct(long long a, long long b, int n)
    {
        long long xa = a & (~((1LL << n) - 1));
        long long xb = b & (~((1LL << n) - 1));

        for (int i = n - 1; i >= 0; --i)
        {
            int bitA = (a >> i) & 1;
            int bitB = (b >> i) & 1;
            if (bitA ^ bitB)
            {
                if (xa > xb)
                {
                    xb |= 1LL << i;
                }
                else
                {
                    xa |= 1LL << i;
                }
            }
            else
            {
                xa |= 1LL << i;
                xb |= 1LL << i;
            }
        }

        const long long mod = 1e9 + 7;
        return (xa % mod) * (xb % mod) % mod;
    }
};